package com.dgut.smart_house.service.impl;

import com.dgut.smart_house.domain.Device;
import com.dgut.smart_house.mapper.ControlMapper;
import com.dgut.smart_house.mapper.DeviceMapper;
import com.dgut.smart_house.service.ControlService;
import com.dgut.smart_house.withHardware.SocketCompent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ControlServiceImpl implements ControlService {

    @Autowired
    ControlMapper controlMapper;
    @Autowired
    DeviceMapper deviceMapper;

    @Autowired
    SocketCompent socket;

    @Override
    public void openDevice(int devId) {
        controlMapper.openDevice(devId);
        Device device=deviceMapper.findDevice(devId);
        socket.getHardwareSocket().sendMsg(device.getCommand() + ":1");
    }

    @Override
    public void closeDevice(int devId) {
        controlMapper.closeDevice(devId);
        Device device=deviceMapper.findDevice(devId);
        socket.getHardwareSocket().sendMsg(device.getCommand() + ":0");
    }


}
